@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 后台相册管理  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr>
            <th>ID</th>
            <th>动态ID</th>
            <th>用户ID</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
        @if(empty($result))
            <tr>
                <td>暂无数据。。。。。。</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        @else
        @foreach($result as $v)
            <tr>
                <td>{{$v->id}}</td>
                <td>{{$v->dm_id}}</td>
                <td>{{$v->dm_user}}</td>
                <td>
                    <img src="{{url("$v->dm_img")}}" height="50px"></td>
                <td>
                    <button class="btn btn-danger" id="but1" onclick="del({{$v->id}})">删除</button>
                </td>
            </tr>
        @endforeach
        @endif
    </table>
    {{$result->links()}}

    <script>
        function del($id) {
            //接收数据
            var id = $id;

            //ajax操作数据
            $.ajax({
                type: 'get',
                url: "{{url('/img/del')}}/" + id,
                data: id,//发送请求
                success: function (data) {

                    if (data == 1) {
                        $("table#tent tr").click(function () {
                            $(this).remove();
                        })
                    window.location.href='{{url('/adm/img')}}';
                    }else{
                        alert('删除失败');
                    }
                },
                error: function () {
                    alert('ajax请求失败');
                }
            });
        }
    </script>

@endsection
